/**
 * 
 _query_list(__BASE_PATH +'page/developAppExt/endCards', '#tagContent0' ,'pagination',{
		rows : 3,
		page : 1,
		isSelfDevCard:"1"
	},  0,__TMPL_HTML,'POST');
 */

/**
 * 
 _query_list(__BASE_PATH +'page/developAppExt/endCards', '#tagContent0' ,'pagination',{
		rows : 3,
		page : 1,
		isSelfDevCard:"1"
	},  0,__TMPL_HTML,'POST');
 */

//查询主体
var _query_list = function(requst_url,_item_wrap,pagination,post_data,_tab_index,__TMPL_HTML,callback,method){
	method = method || "POST";
   // var _item_wrap = $(''+parent_id);
	_item_wrap.empty();
	_item_wrap.append('<div class="_item" style="text-align:center;padding:10px;"><span class="icon_loading"></span></div>');
	
	var fnc = null;
	if("POST" == method){
		fnc = $.post;
	}else{
		fnc = $.get;
	}
	
	fnc(
		requst_url,
		post_data,
		function(result){
			
			//$.messager.progress("close");
			
			//var _item_wrap = $(parent_id);

			_item_wrap.empty();
			
			if(!result || !result.rows ||result.rows.length < 1){
			
				$('<div class="_item" style="text-align: center;">no more result..</div>').appendTo(_item_wrap);
				return false;
			}
			
			if (result.state != 200) {
				$('<div class="_item" style="text-align: center;">failed to query : '+result.message+'</div>').appendTo(_item_wrap);
				return false;
			} 
			

			//$('<div class="_item" style="text-align: center;"></div>').appendTo("#_item_wrap");
			if(callback && typeof callback == 'function'){
                callback();    				
			}
			
			var rows = result['rows'];
			for(var i in rows){
				var item_data = rows[i];
				item_data["_tab_index"] = _tab_index;
				//可以加入默认值的处理
				//item_data["_tab_index"] = _tab_index;
				//item_data["cardNotes"] = _def_value(item_data["cardNotes"],"N/A");
				//if(_is_empty(item_data["cardName"])){
					//item_data["cardName"] = _def_value(item_data["cardTitle"],"N/A");
				//}
				var tmpl_html = _renderTemplate(__TMPL_HTML,item_data);
				var $tmpl_html = $(tmpl_html);
			    //可以加入额外处理
				_item_wrap.append($tmpl_html);
			}
			
			var opt_init = {
					next_text : "下一页",
					prev_text : "上一页",
					link_to : "javascript:void(0);",
					callback : function(current_page, _this){
						//alert(current_page);
						if(post_data.page === current_page + 1){
							return false;
						}
						post_data.page = current_page + 1;
						_query_list(requst_url,_item_wrap,pagination,post_data,_tab_index);
					},
					current_page : post_data.page - 1,
					items_per_page : post_data.rows
			};
			//$(parent_id + " > .pagination")
			$("div.pagination").pagination(result['total'], opt_init);
			
	},"JSON");
};

var callback = function(){
	var _head_html = '<thead><tr><th><input name="" type="checkbox"/></th><th>编号<i class="sort"><img src="'+parent.basePath+parent._image_suffix+'px.gif" /></i></th><th>用户名</th><th>身份证</th>';
	_head_html = _head_html + '<th>性别</th><th>籍贯</th><th>出生日期</th><th>注册时间</th><th>操作</th></tr></thead>';
	$('table.tablelist').append($(_head_html));
};
$(function(){
	var __TMPL_HTML  = $("#tmpl_user_item").html();
	var _item_wrap = $('table.tablelist').find('tbody');
	var pagination = $('div.pagination');
	_query_list(basePath+'sys/Client/list', _item_wrap , pagination,{
			rows : 15,
			page : 1,
			'beanProxy[enable]' :0,
			isSelfDevCard:"1"
		},  0,__TMPL_HTML,callback,'POST');
	
});
